#!/usr/bin/env python3

import collections

Card = collections.namedtuple('Card', ['rank', 'suit'])

class FrenchDeck:

    ranks = [str(n) for n in range(2, 11)] + list("JQKA")
    suits = "spades diamods clubs hearts".split()

    def __init__(self):
        self._cards = [Card(rank, suit) for suit in self.suits
                for rank in self.ranks]

    def __len__(self):
        return len(self._cards)

    def __getitem__(self, position):
        return self._cards[position]


suit_values = dict(spades=3, hearts=2, diamods=1, clubs=0)

def spades_high(card):
    """
    对牌的大小进行排序
    梅花2最小,黑桃A最大
    """
    rank_value = FrenchDeck.ranks.index(card.rank)
    return rank_value * len(suit_values) + suit_values[card.suit]


if __name__ == "__main__":
    #  beer_card = Card('7', 'diamods')
    #  print(beer_card)
    deck = FrenchDeck()
    #  print(deck)
    #  print(len(deck))
    #  print(deck[0])
    #  print(deck[12::13])
    for card in sorted(deck, key=spades_high):
        print(card)
